﻿using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2025-02-21
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 零件信息
    /// </summary>
    [Verify]
    [Route("business/CksPart")]
    [ApiExplorerSettings(GroupName = "business")]
    public class CksPartController : BaseController
    {
        /// <summary>
        /// 零件信息接口
        /// </summary>
        private readonly ICksPartService _CksPartService;

        public CksPartController(ICksPartService CksPartService)
        {
            _CksPartService = CksPartService;
        }

        /// <summary>
        /// 查询零件信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "ckspart:list")]
        public IActionResult QueryCksPart([FromQuery] CksPartQueryDto parm)
        {
            var response = _CksPartService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询零件信息详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "ckspart:query")]
        public IActionResult GetCksPart(int Id)
        {
            var response = _CksPartService.GetInfo(Id);

            var info = response.Adapt<CksPartDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加零件信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "ckspart:add")]
        [Log(Title = "零件信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCksPart([FromBody] CksPartDto parm)
        {
            var modal = parm.Adapt<CksPart>().ToCreate(HttpContext);

            var response = _CksPartService.AddCksPart(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新零件信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "ckspart:edit")]
        [Log(Title = "零件信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCksPart([FromBody] CksPartDto parm)
        {
            var modal = parm.Adapt<CksPart>().ToUpdate(HttpContext);
            var response = _CksPartService.UpdateCksPart(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除零件信息
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "ckspart:delete")]
        [Log(Title = "零件信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCksPart([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CksPartService.Delete(idArr));
        }

    }
}